
log = require 'jass.log'
local log = log

local function split(str, p)
	local rt = {}
	string.gsub(str, '[^]' .. p .. ']+', function (w) table.insert(rt, w) end)
	return rt
end

local function _formatStr(...)
	local str = ""
	local n = select('#', ...)
	local first = tostring(select(1, ...))
	local isFormat = first and string.find(first, "%%")
	if isFormat then
		local args = {}
		for i = 2, n do
			table.insert(args, tostring(select(i, ...)))
		end
		str = string.format(first, table.unpack(args))
	else
		for i = 1, n do
			str = str .. ( n > 1 and '\t' or '') .. tostring(select(i, ...))
		end
	end
	return str
end

log.path = '我的英雄不可能那么萌\\日志\\' .. split(log.path, '\\')[2]
log.debug '日志系统装载完毕,向着星辰大海出击!'

local std_print = print
function print(...)
    local str = _formatStr(...)
	log.info(str)
	return std_print(str)
end

function logInfo(...)
	print(...)
end

local log_error = log.error
function log.error(...)
    local str = _formatStr(...)
	local trc = debug.traceback()
	log_error(str)
	log_error(trc)
	std_print(str)
	std_print(trc)
end
